package io.renren.modules.dangan.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.alicp.jetcache.Cache;
import com.alicp.jetcache.anno.CacheType;
import com.alicp.jetcache.anno.CreateCache;
import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.dangan.entity.DaUserLocationEntity;
import io.renren.modules.dangan.service.DaUserLocationService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * ${comments}
 *
 * @author Mark
 * @email sunlightcs@gmail.com
 * @date 2019-09-02 22:01:22
 */
@RestController
@RequestMapping("danganSys/dauserlocation")
public class DaUserLocationController {
    @Autowired
    private DaUserLocationService daUserLocationService;
    @CreateCache(name = "szdCache", cacheType = CacheType.LOCAL, localExpire = 3600, localLimit = 3000)
    private Cache<Integer, List<String>> szdCache;

    /**
     * 列表
     */
    @RequestMapping("/list")
//    @RequiresPermissions("dangan:dauserlocation:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = daUserLocationService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{recid}")
    @RequiresPermissions("dangan:dauserlocation:info")
    public R info(@PathVariable("recid") String recid){
        DaUserLocationEntity daUserLocation = daUserLocationService.getById(recid);

        return R.ok().put("daUserLocation", daUserLocation);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("dangan:dauserlocation:save")
    public R save(@RequestBody DaUserLocationEntity daUserLocation){
        daUserLocationService.save(daUserLocation);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("dangan:dauserlocation:update")
    public R update(@RequestBody DaUserLocationEntity daUserLocation){
        ValidatorUtils.validateEntity(daUserLocation);
        daUserLocationService.updateById(daUserLocation);
        
        return R.ok();
    }
    /**
     * 先删除原来的，再插入
     */
    @RequestMapping("/updateBatch")
//    @RequiresPermissions("dangan:dauserlocation:update")
    public R updateBatch(@RequestParam("daUserLocationList")  List<String> daUserLocationList, int userId){
        boolean res=daUserLocationService.saveBatch(userId,daUserLocationList);
        if(res){
            return R.ok();
        }else{
            return R.error("保存失败");
        }
    }
    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("dangan:dauserlocation:delete")
    public R delete(@RequestBody String[] recids){
        daUserLocationService.removeByIds(Arrays.asList(recids));

        return R.ok();
    }

}
